package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.DailyPaper;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.mapper.DailyPaperMapper;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.query.DailyPaperQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.query.UserQueryObject;
import cn.wolfcode.trip.base.service.IDailyPaperService;
import cn.wolfcode.trip.base.service.IStrategyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class DailyPaperServiceImpl implements IDailyPaperService {
    @Autowired
    private DailyPaperMapper dailyPaperMapper;


    /**
     * 查询符合关键字的信息条数
     * @param qo
     * @return
     */
    @Override
    public int selectNumByKeyword(DailyPaperQueryObject qo) {
        return dailyPaperMapper.selectNumByKeyword(qo);
    }

    /**
     * 查询对应用户关注的日报信息
     * @param qo
     * @return
     */
    @Override
    public PageInfo queryByUserId(DailyPaperQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<DailyPaper> list = dailyPaperMapper.queryByUserId(qo);
        return new PageInfo<>(list);

    }

    /**
     * 根据用户id和日报id删除对应收藏的数据
     * @param uId
     * @param collectId
     */
    @Override
    public void deleteCollect(Long uId, Long collectId) {
        dailyPaperMapper.deleteCollect(uId,collectId);
    }

    /**
     * 根据用户id和日报id删除对应的点赞数据
     * @param uId
     * @param likeId
     */
    @Override
    public void deleteLike(Long uId, Long likeId) {
        dailyPaperMapper.deleteLike(uId,likeId);
    }

    /**
     * 根据用户id查询他的点赞信息
     * @param uId
     * @return
     */
    @Override
    public List getlike(Long uId) {
        return dailyPaperMapper.getlike(uId);
    }

    /**
     * 添加关注信息
     * @param userId
     * @param collectId
     */
    @Override
    public void addCollect(Long userId, Long collectId) {
        dailyPaperMapper.addCollect(userId,collectId);
    }

    /**
     * 添加点赞信息
     * @param userId
     * @param likeId
     */
    @Override
    public void addLike(Long userId, Long likeId) {
        dailyPaperMapper.addLike(userId,likeId);
    }

    /**
     * 根据用户id查询他的关注信息
     * @param uId
     * @return
     */
    @Override
    public List getCollect(Long uId) {
        return dailyPaperMapper.getCollect(uId);
    }

    /**
     *
     * @param id
     * @return
     */
    @Override
    public DailyPaper getDailyPaperById(Long id) {
        return dailyPaperMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(DailyPaper dailyPaper) {
        if (dailyPaper.getId() != null) {
            dailyPaperMapper.updateByPrimaryKey(dailyPaper);
        }else{
            dailyPaperMapper.insert(dailyPaper);
        }
    }

    /**
     * 列表分页
     * @param qo
     * @return
     */
    @Override
    public PageInfo<DailyPaper> query(DailyPaperQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<DailyPaper> list = dailyPaperMapper.selectForList(qo);
        return new PageInfo<>(list);
    }


}
